package com.gome.controller;


import com.gome.entity.Menu;
import com.gome.exception.GlobalException;
import com.gome.service.MenuService;
import com.gome.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
@Api("权限菜单查询")
@RestController
@RequestMapping("/jservices/menu")
public class MenuController extends  BaseController {

    @Autowired
    private MenuService menuService;

    @ApiOperation(value ="菜单查询",tags = {"获取菜单信息"},notes="测试")
    @ApiImplicitParam(name="nLevel",value="菜单等级")
    @ResponseBody
    @RequestMapping(value = "/queryAllMenu",method ={RequestMethod.GET,RequestMethod.POST})
    public Result queryAllMenu(int nLevel, HttpServletRequest req) throws GlobalException {
        return  menuService.queryAllMenu(nLevel);
    }

    @Transactional
    @ResponseBody
    @ApiOperation(value ="新增菜单")
    @ApiImplicitParam(name="menu",value="菜单对象")
    @RequestMapping(value="/addMenu",method =RequestMethod.POST)
    public Result addMenu( @RequestParam Menu menu,  HttpServletRequest req) throws GlobalException{

        menu.setOcCzy(getUserName(req));
        return   menuService.addMenu(menu);
    }


    @Transactional
    @ResponseBody
    @ApiOperation(value ="修改菜单")
    @ApiImplicitParam(name="menu",value="菜单对象")
    @RequestMapping(value="/updateMenu",method ={RequestMethod.POST})
    public Result updateMenu(Menu menu,HttpServletRequest req) throws GlobalException{
        menu.setOcCzy(getUserName(req));
        return  menuService.updateMenu(menu);

    }
    @Transactional
    @ResponseBody
    @ApiOperation(value ="删除菜单")
    @ApiImplicitParam(name="menu",value="菜单对象")
    @RequestMapping(value="/deleteMenu",method ={RequestMethod.POST})
    public Result deleteMenu(Menu menu,HttpServletRequest req) throws GlobalException{
        menu.setOcCzy(getUserName(req));
        return  menuService.deleteMenu(menu);


    }
    @ResponseBody
    @ApiOperation(value ="查询菜单等级")
    @ApiImplicitParam(value="无参")
    @RequestMapping(value="/ListAllMenuLevel",method ={RequestMethod.POST,RequestMethod.GET})
    public Result ListAllMenuLevel() throws GlobalException{
        return   menuService.getAllMenuLevel();

    }
}
